import { defineStore } from 'pinia'
import { listToTree } from '@/utils/index.js'
export const useStore = defineStore('user', {
  state: () => {
    return {
      userInfo: {},
      userRoles: [],
      jwt: '',
      routeTree: []
    }
  },
  getters: {
    //相当于计算属性
  },
  actions: {
    //更新
    updataUser(user, jwt) {
      this.userInfo = user
      this.jwt = jwt
    },
    fomatRoute(data) {
      this.routeTree = listToTree(data)
    }
  },
  //
  persist: {
    enabled: true,
    strategies: [
      {
        //key的名称
        key: 'pinia',
        //更改默认存储，我更改为localStorage
        storage: localStorage,
        paths: ['jwt', 'userInfo', 'routeTree', 'userRoles'] // 可以选择哪些进入local存储，默认是全部进去存储
      }
    ]
  }
})
